<?php

/*
 * This file is part of the prestaBreadcrumb package.
 * (c) Julien Fusco <jfusco@prestaconcept.net>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */


/**
 * Display the breadcrumb for an array given.
 * 
 * <code>
 *  $breadcrumbs = array(
 *  	array('text' => 'News', 'uri' => '@news'),
 *  	array('text' => 'Article', 'uri' => '@article'),
 *  	// ...
 *  );
 *  display_prestabreadcrumb($breadcrumbs);
 * </code>
 * 
 * <code>
 *  $breadcrumb = prestaBreadcrumb::getInstance()
 *  	->addItem('News', '@news')
 *  	->addItem('Article', '@article')
 *  ;
 *  display_prestabreadcrumb($breadcrumb);
 * </code>
 * 
 * @author 	Julien Fusco
 * @since 	7 déc. 2009
 * @version 1.0 - 7 déc. 2009 - Julien Fusco
 *
 * @param 	Array $breadcrumbs
 * @param 	string $separator
 * @param 	string $template
 */
function display_prestabreadcrumb($breadcrumbs = array(), $separator = null, $template = null)
{
	// $breadcrumbs can be a prestaBreadcrumb object
	if ($breadcrumbs instanceof prestaBreadcrumb)
	{
		$oprestaBreadcrumb = prestaBreadcrumb::getInstance();
	}
	// or an array
	elseif (is_array($breadcrumbs))
	{
		$oprestaBreadcrumb = prestaBreadcrumb::getInstance()
			// first, clear previous items
			->clearItems()
			// redefine root
			->setRoot(sfConfig::get('app_prestaBreadcrumb_home', prestaBreadcrumb::DEFAULT_ROOT), sfConfig::get('app_prestaBreadcrumb_home_uri', prestaBreadcrumb::DEFAULT_ROOT_URI))
			// finally, add items
			->addItemsByArray($breadcrumbs);
		
		// redefine separator
		if (!is_null($separator))
		{
			$oprestaBreadcrumb->setSeparator($separator);
		}
		
		// redefine template
		if (!is_null($template))
		{
			$oprestaBreadcrumb->setTemplate($template);
		}
	}
	
	if ($oprestaBreadcrumb instanceof prestaBreadcrumb)
	{
		echo $oprestaBreadcrumb->render();
	}
}
